package com.jinyi.wwdeng.autodialer.utils.event

import android.content.Intent
import com.jinyi.wwdeng.autodialer.MyApplication

/**
 * 事件通知
 */
object EventAction {
    /* 广播通知 */
    const val ACTION_UPDATE_SERVICE = "com.jinyi.wwdeng.autodialer.ACTION_UPDATE_SERVICE"//更新服务状态
    const val ACTION_UPDATE_DIAL = "com.jinyi.wwdeng.autodialer.ACTION_UPDATE_DIAL"//更新拨号状态
    const val ACTION_UPDATE_UPLOAD = "com.jinyi.wwdeng.autodialer.ACTION_UPDATE_UPLOAD"//更新上传状态
    const val ACTION_UPDATE_REPORT = "com.jinyi.wwdeng.autodialer.ACTION_UPDATE_REPORT"//更新上报状态
    const val ACTION_UPDATE_LOG = "com.jinyi.wwdeng.autodialer.ACTION_UPDATE_LOG"//更新日志
    const val ACTION_UPDATE_TOAST = "com.jinyi.wwdeng.autodialer.ACTION_UPDATE_TOAST"//更新提示

    const val EXTRA_PHONE_NUMBER = "extra_phone_number"
    const val EXTRA_STATUS = "extra_status"
    const val EXTRA_MESSAGE = "extra_message"

    fun sendBroadcast(action: String, vararg extras: Pair<String, Any>) {
        val intent = Intent(action).apply {
            extras.forEach { (key, value) ->
                when (value) {
                    is String -> putExtra(key, value)
                }
            }
        }
        MyApplication.instance.publisher.publish(intent)
    }
}